/**
 * https://www.lodashjs.com/docs/lodash.isPlainObject
 * https://www.jquery123.com/jQuery.isPlainObject/
 * https://yanni4night.github.io/js/2018/02/06/is-plainobject.html
 */
// Load the full build.
var _ = require('lodash');





function Foo() {
  this.a = 1;
}
 
log( _.isPlainObject(new Foo), isPlainObject(new Foo), isObject(new Foo), isJson(new Foo)) ;
// => false
 
log( _.isPlainObject([1, 2, 3]), isPlainObject([1, 2, 3]), isObject([1, 2, 3]), isJson([1, 2, 3])) ;
// => false
 
log( _.isPlainObject({ 'x': 0, 'y': 0 }), isPlainObject({ 'x': 0, 'y': 0 }), isObject({ 'x': 0, 'y': 0 }), isJson({ 'x': 0, 'y': 0 })) ;
// => true
 
log( _.isPlainObject(Object.create(null)), isPlainObject(Object.create(null)), isObject(Object.create(null)), isJson(Object.create(null))) ;
// => true


/**
 * 是否是普通的对象， 包括自定义对象(比如: Person)
 * 这类对象可以转换为json
 * @param  {[type]}  val [description]
 * @return {Boolean}     [description]
 */
function isObject(val) {
  return val != null && typeof val === 'object' && Array.isArray(val) === false;
}


/**
 * 是否为纯对象
 * @return {Boolean} [description]
 */
function isPlainObject() {
	return isPlainObjectV1.apply(null, arguments)
}

function isPlainObjectV1(obj) {
	if (typeof obj !== 'object' || obj === null) return false

	proto = Object.getPrototypeOf(obj);
    if (!proto) {
        return true;
    }

    return obj.constructor === Object
}



/**
 * 判断obj是否为可以转为json的对象
 * @param  {[type]}  obj [description]
 * @return {Boolean}     [description]
 */
function isJson(obj){
	var isjson = typeof(obj) == "object" && 
				Object.prototype.toString.call(obj).toLowerCase() == "[object object]"  && 
				!obj.length; 
	return isjson;
}


function log (... args) {
	let isPrint = 1 ;
	if(!isPrint) return ;
	console.log(...args);
}




